<?php
require_once('../includes/config.php');
?>
<script type="text/javascript">
	$(document).ready( function() {
		//load popup to edit
		$(".edit").click(function(){
			centerPopup();
			loadPopup();
			page=$(this).attr("href");
			$("#popupNews").html("loading...").load(page);
			return false;
		});	
		//hadel del click
		$(".del").click(function(){
			el=$(this);
			if(confirm("Are you sure?"))
			{
				$.ajax({
					url:$(this).attr("href"),
					type:"POST",
					dataType: 'json',
					success:function(data)
					{
						if(data==1)
						{
							el.parent().parent().fadeOut('slow');
						}
						else
						{
							alert(data);
						}
					}
				})
			}
			return false;
		});
	});
</script>
<table id="rounded-corner">
    <thead>
    	<tr>
        	<th scope="col" class="rounded-company"></th>
            <th scope="col" class="rounded">Tiêu Đề</th>
            <th scope="col" class="rounded">Mô Tả</th>
            <th scope="col" class="rounded">Ngày thêm vào </th>
            <th scope="col" class="rounded">Cập nhật lần cuối </th>
            <th scope="col" class="rounded">Sửa</th>
            <th scope="col" class="rounded-q4">Xóa</th>
        </tr>
    </thead>
    <tbody>
	<?php
		
        $textlengh = 30;
        $news_query = "SELECT * FROM tbl_news ORDER BY news_date_added DESC";
        $currentPage = strstr($_SERVER['REQUEST_URI'],'index');
        $itemperPage = 15;
        $result = mysql_query(_getPagingQuery("$news_query", $itemperPage));
        $totalpage = _totalpage("$news_query", $itemperPage);
        $pages = paginate ("index.php?view=news", "page", $totalpage, $currentPage, $itemperPage);
        if(mysql_num_rows($result) > 0)
        {
            while($rows = mysql_fetch_assoc($result))
            {
                extract($rows);
    ?> 
    	<tr>
        	<td><input type="checkbox" name="" /></td>
            <td><a target="_blank" href="../index.php?mod=news&act=ndetail&id=<?php echo $id; ?>"><?php echo $news_title; ?></a></td>
            <td><?php 
						echo mb_substr(strip_tags($news_detail), 0, $textlengh, 'UTF-8');
					  	echo "...";
				?>
            </td>
            <td><?php echo $news_date_added; ?></td>
            <td>
			<?php 
				if($news_lasted_update != "")
				{
					echo $news_lasted_update; 
				}
				else
				{
					echo "Not available";
				}
			?>
            </td>
            <td><a href="news_f.php?act=edit&id=<?php echo $id; ?>" class="edit"><img src="templates/images/user_edit.png" alt="" title="" border="0" /></a></td>
            <td><a href="news_process.php?act=del&id=<?php echo $id; ?>" class="del"><img src="templates/images/trash.png" alt="" title="" border="0" /></a></td>
        </tr>
<?php
    }
}
?>
    </tbody>
</table>
